import dayjs from 'dayjs'
export default {
	data() {
		return {
			dateList: [],
			activeDay: null //当前选择的日期对象
		}
	},

	computed: {

	},

	watch: {
		activeDay: function(val) {
			// 切换日期的时候清空已选择的场次
			this.$store.commit('arena/clearSelectedArena')
			// 获取当前日期下的数据
			this.getList(val.year, val.month, val.date)
		}
	},

	onLoad() {
		const d = dayjs().add(0, 'day')
		this.activeDay = {
			year: d.year(),
			month: d.month() + 1,
			date: d.date(),
			day: d.day()
		}
	},

	onShow() {
		let list = []
		this.getDays(7).forEach(val => {
			list.push({
				year: val.year(),
				month: val.month() + 1,
				date: val.date(),
				day: val.day()
			})
		})
		this.dateList = list
	},

	methods: {
		// 获取以今天开始的 n 天
		getDays(num) {
			const arr = []
			for (let i = 0; i < num; i++) {
				arr.push(dayjs().add(i, 'day'))
			}
			return arr
		}
	}
}
